/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ws.handle;

import com.cxhd.lis.ws.BaseServer;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class StartServer extends BaseServer {

    private Message message = new Message();

    private Gson gson = new Gson();
    private MsgService ms = new MsgService(this);
    private BlockingQueue sendMessageQueue = new LinkedBlockingQueue<Message>();//发送消息的队列

    public StartServer(int port) throws Exception {
        super(port);
    }

    private static StartServer ss;

    public static StartServer getInstance() {
        if (ss == null) {
            try {
                ss = new StartServer(11211);
            } catch (Exception ex) {

            }
            ss.init();
        }
        return ss;
    }

    public void init() {
        ms.start();
    }
    
    public void stopSendThread() throws InterruptedException {
        Message msg = new Message();
        ms.setFlag(false);
        msg.setType("closeServer");
        getSendQueue().put(msg);

    }
        public BlockingQueue getSendQueue() {
//        if (sendMessageQueue == null) {
//            new LinkedBlockingQueue<Message>();
//        }
        return sendMessageQueue;
    }

    @Override
    public void onOpen(ChannelHandlerContext ctx, HttpRequest req) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onMessage(ChannelHandlerContext con, String message) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onClose(ChannelHandlerContext con) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void httpReq(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
